package dating.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dating.model.User;

/**
 * Servlet implementation class Profile
 */
public class Profile extends Application {
	private static final long serialVersionUID = 1L;
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Profile() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if(!isLogged(request)){
			response.sendRedirect("login");
			return;
		}
		
		String userId = request.getParameter("id");
		
		if(userId == null) {
			response.sendRedirect("users");
			return;
		}
		
		long id = Long.parseLong(userId);
		User user = userService.findByPK(id);
		
		request.setAttribute("profile", user);

		render("profile.jsp", request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
